package com.pkq.localdate;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;

public class LocalDateTT {
    public static void main(String[] args) {

        // java 8 中获取日期
        LocalDate now = LocalDate.now();
        System.out.println("当前日期： " + now);
        LocalDate nextDay = now.plusDays(1);
        //下一天
        System.out.println("下一天： " + nextDay);

        // 获取一周后的日期
        LocalDate after_week = now.plus(1, ChronoUnit.WEEKS);
        System.out.println("一周后： " + after_week);

        // 获取本月第一天,最后一天
        LocalDate oneDay = now.with(TemporalAdjusters.firstDayOfMonth());
        System.out.println("本月第一天： " + oneDay);
        LocalDate lastDay = now.with(TemporalAdjusters.lastDayOfMonth());
        System.out.println("本月最后一天： " + lastDay);
        System.out.println("今年第一天： " + now.with(TemporalAdjusters.firstDayOfYear()));
        System.out.println("今年最后一天： " + now.with(TemporalAdjusters.lastDayOfYear()));

        //2021年最后一个周日
        System.out.println("2021年最后一个周日: " + LocalDate.parse("2021-12-31").with(TemporalAdjusters.lastInMonth(DayOfWeek.SUNDAY)));


        LocalTime time = LocalTime.now();
        System.out.println("当前时间： " + time);
        System.out.println("10小时前时间： " + time.plusHours(-10).toString().substring(0, 8));


//        LocalDateTime
        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println("localDateTime = " + localDateTime);

        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String formatTime = pattern.format(localDateTime);
        System.out.println("formatTime = " + formatTime.replace("-", "/"));


    }
}
